<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 21.01.14
 * Time: 21:33
 */

class Tourism_AdminBackgroundController extends Core_Controller_Action_Admin
{
  public function indexAction()
  {
    /** @var $backgroundsTable Tourism_Model_DbTable_Backgrounds*/
    $backgroundsTable = Engine_Api::_()->getDbTable('backgrounds', 'tourism');
    $this->view->backgrounds = $backgroundsTable->fetchAll();
  }

  public function editAction()
  {

  }

  public function createAction()
  {
    $this->view->form = $form = new Tourism_Form_Admin_Background();

    if ($this->getRequest()->isPost()) {
      if ($form->isValid($data = $this->getRequest()->getPost())) {
        /** @var $backgroundsTable Tourism_Model_DbTable_Backgrounds*/
        $backgroundsTable = Engine_Api::_()->getDbTable('backgrounds', 'tourism');
        $background = $backgroundsTable->createRow($data);
        $background->setPhoto($form->photo);
        return $this->_helper->redirector->gotoRoute(array('module' => 'tourism', 'controller' => 'background', 'action' => 'index'), 'admin_default', true);
      }
    }
  }

  public function deleteAction()
  {

  }
}